<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新加坡shopee商品信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>商品编号：</label>
                                <input type="text" name="itemid"/>
                            </li>
                            <li>
                                <label>店铺编号：</label>
                                <input type="text" name="shopid"/>
                            </li>
                            <li>
                                <label>商品链接：</label>
                                <input type="text" name="itemurl"/>
                            </li>
                            <li>
                                <label>货源链接：</label>
                                <input type="text" name="sourceurl"/>
                            </li>
                            <li>
                                <label>币种：</label>
                                <select name="currency" th:with="type=${@dict.getType('shopee_currency')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>所属类别：</label>
                                <input type="text" name="catid"/>
                            </li>
                            <li>
                                <label>已卖数：</label>
                                <input type="text" name="params[beginSold]"/>
                                <span>-</span>
                                <input type="text" name="params[endSold]"/>
                            </li>
                            <li>
                                <label>价格(SG)：</label>
                                <input type="text" name="params[beginPrice]"/>
                                <span>-</span>
                                <input type="text" name="params[endPrice]"/>
                            </li>
                            <li>
                                <label>地址：</label>
                                <input type="text" name="shopLocation"/>
                            </li>
                            <li>
                                <label>标题：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li class="select-time">
                                <label>上架日期：</label>
                                <input type="text" class="time-input" id="sjstartTime" placeholder="开始时间" name="params[beginCtime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="sjendTime" placeholder="结束时间" name="params[endCtime]"/>
                            </li>
                            <li class="select-time">
                                <label>抓取日期：</label>
                                <input type="text" class="time-input" id="zqstartTime" placeholder="开始时间" name="params[beginCrawdate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="zqendTime" placeholder="结束时间" name="params[endCrawdate]"/>
                            </li>
                            <li>
                                <label>国家：</label>
                                <select name="country" th:with="type=${@dict.getType('shopee_country')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>选品状态：</label>
                                <select name="status" th:with="type=${@dict.getType('shopee_select_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="shopee:sgshopeelistinginfo:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="shopee:sgshopeelistinginfo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="shopee:sgshopeelistinginfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="shopee:sgshopeelistinginfo:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('shopee:sgshopeelistinginfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('shopee:sgshopeelistinginfo:remove')}]];
        var currencyDatas = [[${@dict.getType('shopee_currency')}]];
        var countryDatas = [[${@dict.getType('shopee_country')}]];
        var statusDatas = [[${@dict.getType('shopee_select_status')}]];
        var prefix = ctx + "shopee/sgshopeelistinginfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showimageUrl: prefix + "/showimage/{id}",

                modalName: "新加坡shopee商品信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'itemid',
                    title: '商品编号',
                    visible: false
                },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            // var actions = [];
                            // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.itemid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            // // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.itemid + '\')"><i class="fa fa-remove"></i>删除</a>');
                            // return actions.join('');
                            var imageurl=row.images.replace('[','').replace(']','').replace(new RegExp("\'", 'g'), '').split(",");
                            var search1688url='https://s.1688.com/youyuan/index.htm?tab=imageSearch&from=plugin&imageAddress=https://cf.shopee.com.my/file/'+imageurl[0];
                            search1688url= 'https://kj.1688.com/pdt_tongkuan.html?productUrl='+row.itemurl+'&imgurl=https://cf.shopee.com.my/file/'+imageurl[0];
                            // search1688url='https://s.1688.com/youyuan/index.htm?tab=imageSearch&from=plugin&imageType=https://g-search3.alicdn.com&imageAddress=img/bao/uploaded/i4/O1CN01OOxLcp1RW5TkQgd91_!!56972118.png_220x220.jpg';
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.itemid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-success btn-xs fa-plus" href="'+search1688url+'" target="_blank" ><i class="fa fa-edit"></i>1688</a>');
                            return actions.join('');
                        }
                    },
                    {
                        field: 'images',
                        title: '图片',
                        formatter: function(value, row, index) {
                            var imageurl=value.replace('[','').replace(']','').replace(new RegExp("\'", 'g'), '').split(",");
                            console.log(imageurl);
                            return $.table.lazyImageView('https://cf.shopee.com.my/file/'+imageurl[0],'100','100', 'self', row);
                        }
                    },
                    {
                        field: 'sold',
                        title: '已卖数'
                    },
                    {
                        field: 'price',
                        title: '价格',
                        sortable:true,
                        formatter: function(value, row, index) {
                            var actions = [];
                            var finalprice = row.price/100000;
                            actions.push(finalprice);
                            return actions.join('');
                        }
                    },{
                        field: 'ctime',
                        title: '上架日期',
                        sortable:true
                    },
                    {
                        field: 'crawdate',
                        title: '抓取日期'
                    },
                    {
                        title: '商品详情',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs " target="_blank" href="' + row.itemurl + '">商品详情</a> ');
                            return actions.join('');
                        }
                    },
                {
                    title: '店铺链接',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " target="_blank" href=https://id.xiapibuy.com/shop/' + row.shopid + '>' + row.shopid + '</a> ');
                        return actions.join('');
                    }
                },
                {
                    field: 'currency',
                    title: '币种',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(currencyDatas, value);
                    }
                },
                {
                    field: 'catid',
                    title: '所属类别'
                },

                {
                    field: 'shopLocation',
                    title: '地址'
                },
                {
                    field: 'name',
                    title: '标题'
                },


                {
                    title: '货源',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        // console.log('soruce-->'+row.sourceurl )
                        if (row.sourceurl  == null || row.sourceurl .trim() == ""||row.sourceurl =='undefined') {
                            actions.push(value);
                        }else{
                            actions.push('<a class="btn btn-success btn-xs " target="_blank" href="' + row.sourceurl + '">查看货源</a> ');
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'status',
                    title: '选品状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>